<script type="text/javascript" src="/application/js/jquery.itextclear.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
});
</script>
<h1 class="page-title">Paciente: <?php echo $patient['name']?></h1>
<div class="container_12 clearfix leading">
	<div class="grid_12">
		<div id="message"></div>
		<div id="update-patient">
			<form class="form" action="" method="POST" > 
				<input type="hidden" id="id_patient" name="id_patient"  value="<?php echo $patient['id']?>"/>
				<input type="hidden" name="update_patient"  value="1"/>
				<div class="clearfix">
					<label for="form-p_name" class="form-label">Nome <em>*</em></label>
					<div class="form-input"><input type="text" id="form-p_name" name="p_name" placeholder="Nome do Paciente" value="<?php echo $patient['name']?>" /></div>
				</div>
				<div class="clearfix">
					<label for="form-p_age" class="form-label">Idade</label>
					<div class="form-input"><input type="text" id="form-p_age" pattern="[0-9]*" name="p_age" placeholder="Idade" value="<?php echo $patient['age']?>" /></div>
				</div>
				<div class="clearfix">
					<label for="form-p_weight" class="form-label">Peso</label>
					<div class="form-input"><input type="text" id="form-p_weight" pattern="[0-9]*(\.[0-9][0-9]*)*" name="p_weight" placeholder="Peso do Paciente" value="<?php echo $patient['weight']?>"/></div>
				</div>
				<div class="clearfix">
					<label for="form-p_height" class="form-label">Altura</label>
					<div class="form-input"><input type="text" id="form-p_height"  pattern="[0-9]*(\.[0-9][0-9]*)*" name="p_height" placeholder="Altura" value="<?php echo $patient['height']?>"/></div>
				</div>
				<div class="clearfix">
					<label for="form-p_email" class="form-label">Email <em>*</em></label>
					<div class="form-input"><input type="email" id="form-p_email" name="p_email"  required="required" placeholder="Email" value="<?php echo $patient['email']?>"/></div>
				</div>
				<div class="clearfix">
					<label for="form-p_password" class="form-label">Senha <em>*</em></label>
					<div class="form-input"><input type="password" id="form-p_password" name="p_password" required="required" placeholder="Senha" value="<?php echo $patient['password']?>"/></div>
				</div>
				<div class="clearfix">
					<label for="form-p_password2" class="form-label">Confirmar a Senha <em>*</em></label>
					<div class="form-input"><input type="password" data-equals="p_password" id="form-p_password2" name="p_password2" required="required" placeholder="Repita a Senha" value="<?php echo $patient['password']?>"/></div>
				</div>					
				<div class="form-action clearfix">
					<div class="button back"><< Voltar</div>
					<div class="button submit">Atualizar</div>
					<div class="button remove">Excluir Paciente</div>
				</div>
			</form>
		</div>
	</div>
</div>
<script>
	$(document).ready(function(){
		$('.button.submit').click(function() {
			form = $('form');
			data = form.serializeArray();
			$.post('/ajax/upload_patient',data,function(r){
				$('#message').html('<div class="message success closeable">	<span class="message-close"></span><h3>Sucesso!</h3><p> Os dados do paciente foram atualizados!</p></div>');
			});
		});
		$('.button.remove').click(function() {
			response = confirm("Você realmente deseja apagar o registro do paciente?");
			if (response){
				data = {
					remove_patient : 1,
					id_patient : $('#id_patient').val()
				}
				$.post('/ajax/remove_patient',data,function(r){
					location.hash = "#pacientes";
				});
			} 
		});
		
		$('.button.back').click(function() {
			location.hash = "#pacientes";
		});
	});
</script>